package com.dream.essearch.model.entity;

import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @description: 文章Doc
 * @author: LiMG
 * @create: 2025-04-28 00:53:23
 **/
@Data
@NoArgsConstructor
public class BookDoc {

    private String id;

    private String title;

    private Double price;

    private String author;

    private String publisher;

    private String description;

    private String imageUrl;

    private List<String> suggestion;

    private String createTime;

    private String updateTime;

    public BookDoc(BookEntity book) {
        this.id = book.getId();
        this.title = book.getTitle();
        this.price = book.getPrice();
        this.author = book.getAuthor();
        this.publisher = book.getPublisher();
        this.description = book.getDescription();
        this.imageUrl = book.getImageUrl();
        this.createTime = book.getCreateTime();
        this.updateTime = book.getUpdateTime();
        // 自动补全字段的处理
        this.suggestion = new ArrayList<>();
        // 添加书名、作者、出版社
        this.suggestion.add(this.title);
        this.suggestion.add(this.publisher);
        if (this.author.contains("，")) {
            Collections.addAll(this.suggestion, this.author.split("，"));
        } else {
            this.suggestion.add(this.author);
        }
    }
}
